<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /* 
            时间O(N)
            空间O(1)
        */
        var moveZeroes = (nums) => {
            if (nums.length === 0) return 0
            if (nums.length === 1) return nums
            let fastIndex = 0;
            let slowIndex = 0;
            for (; fastIndex < nums.length; fastIndex++) {
                // 只有不存在重复值时，slowIndex才可以进行扩展
                if (nums[fastIndex] !== 0) {
                    // 必须是交换快慢这两个元素
                    let temp = nums[fastIndex]
                    nums[fastIndex] = nums[slowIndex]
                    nums[slowIndex] = temp
                    slowIndex++
                }
            }
            return nums
        };
        // console.log(moveZeroes([0,1,0,3,12]));
        // console.log(moveZeroes([0,1,0,3, 0, 12, 0, 13]));
        // console.log(moveZeroes([1]));
        console.log(moveZeroes([1, 0]));
    </script>
</body>

</html>